#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int h[N];
int n;
bool check(int e)
{
	for (int i = 1; i <= n; i++) {
		e = 2 * e - h[i];
		if (e < 0) {
			return 0;
		}
		if (e > 1e5) {	
			return 1;
		}
	}
	return 1;
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	int l = 0;
	int r = 1e5;
	while (l < r) {
		int mid = l + r >> 1;
		if (check(mid)) {
			r = mid;
		}
		else {
			l = mid + 1;
		}
	}
	cout << r << endl;
	return 0;
}